﻿using MediatR;
using T_vehicle.API.Application.Command.IllegalCommand;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.IllegalCommandHandlers
{
    public class PDelIllgalCommandHandlers:IRequestHandler<PDelIllgalCommand,int>
    {
        private readonly IIllegalRepository illegalRepository;

        public PDelIllgalCommandHandlers(IIllegalRepository illegalRepository)
        {
            this.illegalRepository = illegalRepository;
        }

        public  async Task<int> Handle(PDelIllgalCommand request, CancellationToken cancellationToken)
        {
            var IllegalId = request.IllegalId.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await illegalRepository.GetAsync(x=>IllegalId.Contains(x.IllegalId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await illegalRepository.UpdateAsyncRange(list);
        }
    }
}
